package com.qf.commerce.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.commerce.common.dto.SeckillActivityDto;
import com.qf.commerce.entity.SeckillActivityProduct;
import com.qf.commerce.exception.ServiceException;
import com.qf.commerce.mapper.SeckillActivityProductMapper;
import com.qf.commerce.resp.ResponseStatus;
import com.qf.commerce.service.SeckillActivityProductService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
@Service
public class SeckillActivityProductServiceImpl implements SeckillActivityProductService {
    @Resource
    SeckillActivityProductMapper seckillActivityProductMapper;
    @Override
    public PageInfo<SeckillActivityProduct> queryCommodity(Integer page, Integer size, SeckillActivityDto seckillActivityDto) {
        PageInfo<SeckillActivityProduct> pageInfo = PageHelper.startPage(page, size).doSelectPageInfo(() -> seckillActivityProductMapper.selectProduct(seckillActivityDto));
        if(ObjectUtils.isEmpty(pageInfo)){
            throw  new ServiceException(ResponseStatus.DATA_ERROR);
        }
        return pageInfo;
    }
}
